#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <queue>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifndef TEST
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> piii;

// fast input
inline ll read() {
    ll X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch))
        X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}

// fast output
inline void write(ll x) {
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}

#define pb push_back
#define mp make_pair

void solve() {
    int n = read(), k = read();
    vector<pii> v;
    for (int i = 0; i < n; i++) {
        int p = read(), d = read();
        v.pb({p, d});
    }
    sort(v.begin(), v.end());
    ll tmp = 0;
    for (int i = 0; i <= 30; i++) {
        ll k1 = k;
        if ((1 << i) & k) {
            k1 = k & ~(1 << i);
            k1 |= (1 << i) - 1;
        }
        ll ans = 0;
        for (auto pa : v) {
            auto p = pa.first, d = pa.second;
            if ((p | k1) == k1) {
                ans += d;
            }
        }
        tmp = max(tmp, ans);
    }
    write(tmp);
    putchar('\n');
}

int32_t main() {
    int t = 1;
    while (t--) {
        solve();
    }
}